package view.actionlisteners;

import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;

import view.AddressView;

public final class SpeicherButtonActionListener implements ActionListener {
	private final AddressView addressView;

	public SpeicherButtonActionListener(AddressView addressView) {
		this.addressView = addressView;
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		this.addressView.retrieveFields();
		
		this.addressView.addressListView.addAddress (this.addressView.address);
		
		Container container = (Container) e.getSource();
		while (!((container = container.getParent()) instanceof JFrame));
		((JFrame) container).setVisible(false);
		((JFrame) container).dispose();
	}
}